<template>
	<!-- <div>
		<u--image class=".tabbar-box-item" :showLoading="true" :src="src" width="200px" height="200px" shape="circle" style=""></u--image>
		<u-button text="按钮" @click="login"></u-button>
	</div> -->
	<view class="app">
		<div class="imgDiv">
			<image :src="src" 
			style="width: 100%;
				   height: 100%;
				   ">
		   </image>
		</div>
		<button type="primary" @click="login">
			<view class="item column center">
				授权登录
			</view>
		</button>
	</view>
</template>

<script>
	export default {
		created() {			
			let that = this
			this.$api.isLogin().then(res => {
				if (res.code == 0) {
					uni.switchTab({
						url: that.tab1
					})
				}
			})
		},
		data() {
			return {
				tab1: '/pages/tabbar/tabbar-1/tabbar-1',
				isLogin: false,
				token: '',
				src: 'https://kiliter.oss-cn-shanghai.aliyuncs.com/%E7%BD%91%E7%AB%99/%E7%8C%AB%E7%88%AA.png'
			};
		},
		methods: {
			login() {
				let that = this;
				let api = this.$api
				uni.getUserProfile({
					desc: "获取用户信息用于登录",
					success: (res) => {
						let user = res.userInfo
						uni.login({
							provider: 'weixin',
							success: function({
								code
							}) {
								api.login({
									img: user.avatarUrl,
									nickName: user.nickName,
									sex: user.gender,
									code: code
								}).then(res => {
									if (res.code == 0) {
										console.log(res.data)
										uni.setStorageSync('user', res.data)
										uni.switchTab({
											url: that.tab1
										})
									}
								})
							}
						});
					}
				})
			},

		}
	};
</script>
<style>
	.app {
		text-align: center;
		padding: 20px;
	}

	.imgDiv {
		width: 300rpx;
		height: 300rpx;
		margin: 100px auto;
	}

	.mt20 {
		margin-top: 20px;
	}
</style>
